<?php
	$strSearch = '';
	$strSearchRight = '';
?>

<div class="appContent">
	<form action="" method="post" name="appForm">
		<?php echo $this->render($this->arrParam['controller'] . '/toolbar/index.php');?>
		<div class="formList goc5">
			<div class="appTop goct5">
				<div class="block_filter">
					<div class="fl">
						<div class="listSearch">
							<?php echo $strSearch; ?>
							<div class="clr"></div>			
						</div>
					</div>
					<div class="fr">
						<div class="listSelect">
							<?php echo $strSearchRight;?>
							<div class="clr"></div>
						</div>
					</div>
					<div class="clr"></div>
				</div>
			</div>
			<div class="appBody" style="padding-bottom: 10px;">
				<div class="dragbox width33" id="listFilter">
					
				</div>
				<div style="width: 66%; float: right;">
					<?php
						$content = $this->cmsEditor('content',htmlspecialchars_decode($this->Item['content']),array('toolbar'=>'MyToolbar', 'language'=>'vi', 'skin' => 'v2'), 'auto', 200, true, 500, false);
						echo $content;
					?>
					<div class="tblButton" style="margin-bottom: 10px;">
						<a onclick="thaytheFilter()" id="thaytheFilter" href="javascript:void(0)" class="button goc5">Thay thế nội dung</a>
					</div>
					<div id="noidungthaythe"></div>
				</div>
				<div class="clr"></div>
			</div>
		</div>
		<div id="dialog-form" title="Từ khóa thay thế" style="display:none;">
			<table class="tbl">
				<tr>							
					<td width="120">Số tiền đóng <span class="red font11">(VNĐ)</span></td>
					<td><input type="text" name="name" id="popup_sotien" class="txtmedium auto_numberic" value=""/></td>
				</tr>
			</table>
		</div>
	</form>
	<script type="text/javascript">
		function loadFilter(){
			$('#listFilter').load('<?php echo $this->baseUrl('seo/ajax/index');?>');
		}
		function addFilter(){
			$('#dialog-form').remove();
			$('body').append('<div id="dialog-form" title="Thêm mới từ thay thế" style="display:none;"></div>');
			$('#dialog-form').load('<?php echo $this->baseUrl('seo/ajax/add');?>');
            $("#dialog-form").dialog({
                modal: true,
                height: 250,
                width: 410,
                buttons: {
                	"Lưu lại": function() {
                		$.ajax({
							url: '<?php echo $this->baseUrl('seo/ajax/add');?>',
							type: 'POST',
							dataType: 'html',
							data: { 
								name : $('#name').val()
							},
							beforeSend: function(){},
						 	success: function(html){
						 		loadFilter();
							}
						});
                		$( this ).dialog( "close" );
					},
                	"Hủy bỏ": function() {
                		$( this ).dialog( "close" );
                	}
                }
            });
		}
		function editFilter(id){
			$('#dialog-form').remove();
			$('body').append('<div id="dialog-form" title="Thêm mới từ thay thế" style="display:none;"></div>');
			$('#dialog-form').load('<?php echo $this->baseUrl('seo/ajax/edit/id/');?>' + id);
            $("#dialog-form").dialog({
                modal: true,
                height: 250,
                width: 410,
                buttons: {
                	"Lưu lại": function() {
                		$.ajax({
							url: '<?php echo $this->baseUrl('seo/ajax/edit/id/');?>' + id,
							type: 'POST',
							dataType: 'html',
							data: { 
								name : $('#name').val()
							},
							beforeSend: function(){},
						 	success: function(html){
						 		loadFilter();
							}
						});
                		$( this ).dialog( "close" );
					},
                	"Hủy bỏ": function() {
                		$( this ).dialog( "close" );
                	}
                }
            });
		}
		function statusFilter(type,id){
			$.ajax({
				url: '<?php echo $this->baseUrl('seo/ajax/status/type/');?>' + type + '/id/' + id,
				type: 'POST',
				dataType: 'html',
				data: { 
					type : type,
				},
				beforeSend: function(){},
			 	success: function(html){
			 		loadFilter();
				}
			});
		}
		function deleteFilter(id){
			if(confirm('Bạn có muốn xóa thật không?')) {
				$.ajax({
					url: '<?php echo $this->baseUrl('seo/ajax/delete/id/');?>' + id,
					type: 'POST',
					dataType: 'html',
					data: { 
						id : id,
					},
					beforeSend: function(){},
				 	success: function(html){
				 		loadFilter();
					}
				});
			}
		}
		function thaytheFilter(){
			$('#noidungthaythe').html('');
			$('body').append('<div class="loading_page"></div>');
			var arrFilter = new Array();
			var i = 0;
			$('.danhsach_tukhoa').each(function(index){
				if($('#status', this).attr('data') == 0) {
					arrFilter[i] = $('#tukhoa', this).text();
					i++;
				}
			});
			$.ajax({
				url: '<?php echo $this->baseUrl('seo/ajax/thaythe');?>',
				type: 'POST',
				dataType: 'html',
				data: { 
					content : CKEDITOR.instances['content'].getData(),
					arr_filter : arrFilter
				},
				beforeSend: function(){},
			 	success: function(html){
			 		$('#noidungthaythe').html(html);
			 		$('.loading_page').remove();
				}
			});
		}		
		$(document).ready(function(){
			loadFilter();
		});
	</script>
</div>
<div class="clr"></div>	
